home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / HELLO.ZIP / os2 / HELLO.CMD next >
Encoding:
Text File  |  1996-04-04  |  13.2 KB  |  369 lines

  1. /******************************* REXX *********************************/
  2. /*     REXX program to calculate and display current date and         */
  3. /*     time, and pop up daily reminders.                              */
  4. /**********************************************************************/
  5. /*  This program is a port of a program originally written in ANSI    */
  6. /*  COBOL.   The original COBOL program and this REXX port were done  */
  7. /*  by the same programmer, Jaime A. Cruz, Jr.  This program will     */
  8. /*  read an ASCII flat file and produce a pop-up window with an       */
  9. /*  appropriate greeting followed by a list of reminders.  For more   */
  10. /*  information on the flat file, view HELLO.DAT, which contains      */
  11. /*  some sample dates and directions on how to add your own.  There   */
  12. /*  are several external subroutines invoked by this program.  Refer  */
  13. /*  to JCCalJul, JCDoM, JCDoW, JCEaster, JCJulCal, JCLepYer, and      */
  14. /*  JCSort for further information.                                   */
  15. /*                                                                    */
  16. /*  This program is released to the public domain.  Share it with     */
  17. /*  your friends.  It is easy enough to port to other platforms.      */
  18. /*  For  example, the author also has a mainframe version that runs   */
  19. /*  under TSO/E.  Use "EXECIO" instead of "LineIn" to process the     */
  20. /*  data.  Don't forget to allocate the file before issuing the       */
  21. /*  EXECIO commands.  The allocation step is not necessary for a      */
  22. /*  VM/CMS port.  Enjoy!  The author may be contacted at              */
  23. /*  72267.1372@compuserve.com, or jcruz@ibm.net                       */
  24. /**********************************************************************/
  25. quit_hour = '17'                 /* Default hour for quitting time    */
  26. quit_min = '00'                  /* Default minutes for quitting time */
  27. data = 'C:\HELLO.DAT'            /* File containing red-letter dates  */
  28. outline. = ''
  29. outline.max = 0                  /* Maximum length of output line     */
  30. outline.0 = 0                    /* Table of output lines             */
  31.  
  32. /**********************************************************************/
  33. /*                          Table of months                           */
  34. /**********************************************************************/
  35. month.0 = 12
  36. month.1 = 'January'
  37. month.2 = 'February'
  38. month.3 = 'March'
  39. month.4 = 'April'
  40. month.5 = 'May'
  41. month.6 = 'June'
  42. month.7 = 'July'
  43. month.8 = 'August'
  44. month.9 = 'September'
  45. month.10 = 'October'
  46. month.11 = 'November'
  47. month.12 = 'December'
  48.  
  49. /**********************************************************************/
  50. /*          Table of comments to make based on day of week.           */
  51. /**********************************************************************/
  52. comment.0 = 7
  53. comment.1 = 'Happy Monday!  <GROAN...>'
  54. comment.2 = 'I think you''ll make it...'
  55. comment.3 = 'It''s all downhill from here'
  56. comment.4 = 'Hang in there, Baby, Friday''s coming'
  57. comment.5 = ''
  58. comment.6 = 'You''re working on a weekend?'
  59. comment.7 = comment.6
  60.  
  61. /**********************************************************************/
  62. /*                Set up some initial default values.                 */
  63. /**********************************************************************/
  64. day = Date('S')
  65. Parse Value day With 1 year 5 ,
  66.                      5 mm 7 ,
  67.                      7 dd 9
  68. mm = Strip(mm, 'L', '0')
  69. dd = Strip(dd, 'L', '0')
  70. century = Left(year, 2) || '00'
  71. today = Left(year, 2) || JCCalJul(Date('U'))
  72. current = Time('C')
  73. Parse Value current With hh ':' min
  74. min = Left(min, 2)
  75. d_o_w = (Date('B') // 7) + 1                /* Calculates day of week */
  76.  
  77. /**********************************************************************/
  78. /*            Determine the appropriate greeting to use.              */
  79. /**********************************************************************/
  80. If Right(current, 2) = 'pm' Then
  81.    Do
  82.       If hh \= 12 Then
  83.          hours = hh + 12
  84.       Else
  85.          hours = hh
  86.       If hh < 6 | hh = 12 Then
  87.          day_greet = 'afternoon'
  88.       Else
  89.          day_greet = 'evening'
  90.    End
  91. Else
  92.    Do
  93.       day_greet = 'morning'
  94.       If hh \= 12 Then
  95.          hours = hh
  96.       Else
  97.          hours = 0
  98.    End
  99.  
  100. /**********************************************************************/
  101. /*          Calculate the quitting time into civilian-speak           */
  102. /**********************************************************************/
  103. If quit_hour > 12 Then
  104.    Do
  105.       q_hour = quit_hour - 12
  106.       am_or_pm = 'pm'
  107.    End
  108. Else
  109.    Do
  110.       q_hour = quit_hour
  111.       am_or_pm = 'am'
  112.    End
  113.  
  114. /**********************************************************************/
  115. /*                   Display the initial greeting.                    */
  116. /**********************************************************************/
  117. Call PutLine 'Good' day_greet || '!  Today is' Date('W') || ',' ,
  118.              month.mm dd || ',' year || ','
  119. Call PutLine 'and it is now' current || '.'
  120. Call PutLine 'If your quitting time is' q_hour || ':' || quit_min || ,
  121.              am_or_pm 'then'
  122.  
  123. /**********************************************************************/
  124. /*          Display an appropriate "Quitting Time" remark.            */
  125. /**********************************************************************/
  126. If (hours > quit_hour) | ,
  127.    ((hours = quit_hour) & ,
  128.     (min > quit_min)) Then
  129.    Call PutLine 'you shouldn''t even be here!'
  130. Else
  131.    If (hours = quit_hour) & ,
  132.       (min = quit_min) Then
  133.       Call PutLine 'you can leave now!'
  134.    Else
  135.       Do
  136.          If min > quit_min Then
  137.             Do
  138.                quit_min = quit_min + 60
  139.                quit_hour = quit_hour - 1
  140.             End
  141.          quit_hour = quit_hour - hours
  142.          quit_min = quit_min - min
  143.          If quit_min = 1 Then
  144.             sm = ''
  145.          Else
  146.             sm = 's'
  147.          If quit_hour = 1 Then
  148.             sh = ''
  149.          Else
  150.             sh = 's'
  151.          If (quit_hour > 0) & ,
  152.             (quit_min > 0) Then
  153.             Call PutLine 'you only have' quit_hour 'hour' || sh ,
  154.                          'and' quit_min 'minute' || sm 'left to go!'
  155.          Else
  156.             If quit_min = 0 Then
  157.                Call PutLine 'you only have' quit_hour 'hour' || sh ,
  158.                             'to go!'
  159.             Else
  160.                Call PutLine 'you only have' quit_min 'minute' || sm ,
  161.                             'to go!'
  162.       End
  163.  
  164. /**********************************************************************/
  165. /*         Display an appropriate "Time till Friday" remark.          */
  166. /**********************************************************************/
  167. If d_o_w = 5 Then
  168.    Call PutLine 'Thank God it''s Friday!  Have a good weekend.'
  169. Else
  170.    Do
  171.       x = 5 - d_o_w
  172.       If x < 0 Then
  173.          x = x + 7
  174.       If x > 1 Then
  175.          sd = 's'
  176.       Else
  177.          sd = ''
  178.       Call PutLine 'Only' x 'more day' || sd 'to Friday (' || ,
  179.                    comment.d_o_w || ').'
  180.    End
  181.  
  182. /**********************************************************************/
  183. /*     Here's the biggie.  Read in the file containing red-letter     */
  184. /*     dates, and load up a table with this information.              */
  185. /**********************************************************************/
  186. x = 0
  187. Do While Lines(data) > 0
  188.    line = Linein(data)
  189.    perpdate = 0
  190.    Parse Value line With 1 cardgdat 9 ,
  191.                          9 cardtrgr 11 ,
  192.                          11 cardday 72 .
  193.    Select
  194.       When Datatype(Left(cardgdat, 2), 'N') Then
  195.          Nop                                   /* Valid Calendar date */   
  196.       When Translate(Left(cardgdat, 1)) = '*' Then
  197.          Iterate                                /* Skip comment lines */
  198.       When Translate(Left(cardgdat, 1)) = 'R' Then
  199.          Do                                  /* Relative day of month */
  200.             tmp = JCDoM(Substr(cardgdat, 2, 4))
  201.             cardgdat = Left(tmp, 6) || Right(tmp, 2)
  202.          End
  203.       When Translate(Left(cardgdat, 1)) = 'E'  Then
  204.          Do                                /* Date relative to Easter */
  205.             If easter = 'EASTER' Then
  206.                easter = Right(JCEaster(year), 5)
  207.             offset = Strip(Substr(cardgdat, 2, 3))
  208.             If offset = '' Then
  209.                offset = 0
  210.             cardgdat = JCJulCal(easter + offset)
  211.          End
  212.       Otherwise
  213.          Nop
  214.    End
  215.    If Right(cardgdat, 2) = '  ' Then
  216.       Do
  217.          cardgdat = Left(cardgdat, 5) || '/' || year
  218.          perpdate = 1
  219.       End
  220.    Else
  221.       Do
  222.          tmp = Right(cardgdat, 2)
  223.          tmp = century + tmp
  224.          cardgdat = Left(cardgdat, 6) || tmp
  225.       End
  226.    jul_date = JCCalJul(cardgdat)
  227.    trig_year = Left(jul_date, 4)
  228.    trig_day = Right(jul_date, 3)
  229.    cardtrgr = Strip(cardtrgr)
  230.    If Datatype(cardtrgr, 'N') Then
  231.       trigger = cardtrgr
  232.    Else
  233.       trigger = 14
  234.    trig_day = trig_day - trigger
  235.    If trig_day < 1 Then
  236.       Do
  237.          e_o_y = 1
  238.          trig_day = Right(jul_date, 3)
  239.          If \ perpdate Then
  240.             trig_year = trig_year - 1
  241.          If JCLepYer(trig_year) Then
  242.             trig_day = trig_day + 366
  243.          Else
  244.             trig_day = trig_day + 365
  245.          y = Right(trig_year, 4, '0') || Right(trig_day, 3, '0')
  246.          dummy_entry = y - trigger
  247.          dummy_entry = dummy_entry y
  248.          date_trigger = Left(jul_date, 4) || ,
  249.                         '001'
  250.       End
  251.    Else
  252.       Do
  253.          e_o_y = 0
  254.          date_trigger = Right(trig_year, 4, '0') || ,
  255.                         Right(trig_day, 3, '0')
  256.       End
  257.    If date_trigger <= today & ,
  258.       jul_date >= today Then
  259.       Do
  260.          x = x + 1
  261.          table.x = date_trigger ,
  262.                    jul_date ,
  263.                    Strip(cardday)
  264.       End
  265.    If e_o_y Then
  266.       Do
  267.          x = x + 1
  268.          table.x = dummy_entry ,
  269.                          Strip(cardday)
  270.       End
  271. End
  272. line = Lineout(data)
  273. table.0 = x
  274.  
  275. /**********************************************************************/
  276. /*       Table has been loaded.  Sort into ascending sequence         */
  277. /**********************************************************************/
  278. Do x = 0 To table.0
  279.    Queue table.x
  280. End
  281. Call JCSort
  282. Do x = 0 To table.0
  283.    Parse Pull table.x
  284. End
  285.  
  286. /**********************************************************************/
  287. /*                Display upcoming red-letter dates.                  */
  288. /**********************************************************************/
  289. Do x = 1 To table.0
  290.    Parse Var table.x trig_date actual_date holiday_name
  291.    If trig_date > today Then
  292.       Leave
  293.    If actual_date >= today Then
  294.       Do
  295.          If actual_date = today Then
  296.             Call PutLine 'Happy' holiday_name
  297.          Else
  298.             Do
  299.                y = actual_date - today
  300.                weeks_left = y % 7
  301.                days_left = y // 7
  302.                If days_left = 1 & ,
  303.                   weeks_left = 0 Then
  304.                   Call PutLine 'Tomorrow is' holiday_name
  305.                Else
  306.                   Do
  307.                      If days_left = 1 Then
  308.                         sd = ''
  309.                      Else
  310.                         sd = 's'
  311.                      If weeks_left = 1 Then
  312.                         sw = ''
  313.                      Else
  314.                         sw = 's'
  315.                      If weeks_left \= 0 & ,
  316.                         days_left \= 0 Then
  317.                         Call PutLine 'Only' weeks_left 'week' || sw ,
  318.                                      'and' days_left 'day' || sd ,
  319.                                      'till' holiday_name
  320.                      Else
  321.                         If weeks_left = 0 Then
  322.                            Call PutLine 'Only' days_left 'more days' ,
  323.                                         'till' holiday_name
  324.                         Else
  325.                            Call PutLine 'Only' weeks_left ,
  326.                                         'more week' || sw 'till' ,
  327.                                         holiday_name
  328.                   End
  329.             End
  330.       End
  331. End
  332.  
  333. /**********************************************************************/
  334. /*     Display the information in a pop-up message box for user       */
  335. /**********************************************************************/
  336. Call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  337. initcode = VInit()
  338. If initcode \= 'ERROR' Then
  339.    Do
  340.       Call VDialogPos 50, 50
  341.       done = 0
  342.       x = 0
  343.       msg.0 = 10                     /* Maximum ten lines for display */
  344.       Do Until done
  345.          Do y = 1 To msg.0
  346.             x = x + 1
  347.             msg.y = Left(outline.x, outline.max)
  348.          End
  349.          Call VMsgBox 'Hello!', msg, 1
  350.          If x >= outline.0 Then
  351.             done = 1
  352.       End
  353.    End
  354. Call VExit
  355. Exit
  356.  
  357. /**********************************************************************/
  358. /*           Subroutine to display information to the user            */
  359. /**********************************************************************/
  360. PutLine:
  361.    Procedure Expose outline.
  362.    Parse Arg line_out
  363.    outline.0 = outline.0 + 1
  364.    x = outline.0
  365.    outline.x = line_out
  366.    If Length(line_out) > outline.max Then
  367.       outline.max = Length(line_out)
  368. Return 0
  369.